{% extends "aside/erp/base.html" %}
{% load staticfiles %}
{% block custom_tdk %}
    <title>产品库管理 - WanFeng</title>
    <meta name="description" content="产品库管理">
    <script src="{% static '' %}aside/scripts/app/jquery-1.10.2.min.js"></script>
{% endblock %}

{% block page-title %}产品库管理{% endblock %}

{% block app-footer %}
    <div class="app-footer white bg p-a b-t">


    <div class="pull-right text-sm text-muted"></div>
    <span class="text-sm text-muted">WanFeng &copy; Copyright. Version 4.0.1</span>
</div>
{% endblock %}

{% block app-body %}


<input type="hidden" id="UserID" name="UserID" value="{{ request.user.id }}"/>

<div class="padding">
<div class="box">



<div class="row p-a" id="filterBox" style="display: none;">



</div>


<div class="row p-a">
    <div class="col-sm-6">
                <button class="btn btn-fw dark text-white" data-toggle="modal" data-target="#modal-edit">添加产品库商品</button>
        </div>
    <form name="searchFrom" action="" id="searchFrom">


        <div class="col-sm-6">
            <div class="input-group">

                <input type="hidden" id="searchType" name="searchType" value="1"/>
                <div class="input-group-btn dropdown">
                    <button type="button" class="btn btn-sm white dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
                        <span id="searchTypeText">搜索类型</span>
                        <span class="caret"></span>
                    </button>
                    <div class="dropdown-menu">
                        <a class="dropdown-item setSearchType" href="javascript:" data-val="1">标题</a>
                        <a class="dropdown-item setSearchType" href="javascript:" data-val="2">产品ID</a>
                         </div></div>
                <input type="text" class="form-control" name="searchTxt" placeholder="搜索" style="height:1.7rem;font-size: 14px;" {% if searchTxt %}value="{{ searchTxt }}"{% endif %}>
                <span class="input-group-btn">
                <button class="btn btn-sm white" type="submit"><i class="fa fa-search"></i></button>
                </span>

            </div>
        </div>
    </form>
</div>

<div class="table-responsive">

    <table class="table table-striped table-hover b-t">
        <thead>
        <tr>
            <th style="width:20px"><label class="ui-check m-a-0">
                <input type="checkbox" id="action-toggle">
                <i></i></label></th>
            <th>ID</th>
            <th>主图</th>
            <th>标题</th>
            <th>重量</th>
            <th>采购厂家</th>
            <th style="min-width: 60px">采购链接</th>
            <th style="width: 60px">备注</th>
            <th>创建时间</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody id="goodsListBox">
        {% for product in productData %}
        <tr data-val="{{ product.ID }}" >
            <td><label class="ui-check m-a-0">
                <input type="checkbox" name="post[]">
                <i class="dark-white"></i></label></td>
            <td>{{ product.ID }}</td>
            <td><img src="{{ product.IMAGE }}" class="w-96 img-responsive" alt=""/></td>
            <td>{{ product.NAME }} </td>
            <td>{{ product.PRODUCTWEIGHT }}</td>
            <td>{{ product.CHANGJIANAME }}</td>
            <td>{{ product.CHANGJIAURL }}</td>
            <td>{{ product.NOTE }}</td>
            <td>{{ product.CREATE_TIME }}</td>
            <td class="text-right">
                <button class="btn btn-sm btn-icon white" data-toggle="modal" data-target="#modal-edit"><i class="fa fa-edit edits" data-toggle="tooltip" data-placement="bottom" title="编辑" onclick="etEditPage({{ product.ID }})"></i></button>
                <button class="btn btn-sm btn-icon white setOffline" data-toggle="modal" data-target="#modal-setOffline"><i class="fa fa-sign-out" data-toggle="tooltip" data-placement="bottom" title="删除"></i></button>
            </td>
        </tr>
        {% endfor %}
        </tbody>
    </table>
</div>


<div id="modal-edit" class="modal black-overlay" data-backdrop="false">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">编辑 <a data-dismiss="modal" class="pull-right text-muted text-lg p-a-sm m-r-sm">×</a></h5>
            </div>
            <div class="modal-body text-center p-lg m-l-1 m-r-3">
                <form role="form" id="editSubjectForm" action="" method="post">
                    {% csrf_token %}
                    <input type="hidden" id="productId" name="productId" value="0"/>
                    <div class="" id="editSubjectItems">
                        <div class="form-group row">
                        <label for="editSubjectEn" class="col-sm-2 form-control-label">产品编号：</label>
                            <div class="col-sm-10">
                                 <input class="form-control" type="text" id="NUMBERS" name="NUMBERS" value="">
                            </div>
                        </div>
                        <div class="form-group row">
                        <label for="editSubjectEn" class="col-sm-2 form-control-label">标题：</label>
                            <div class="col-sm-10">
                                 <input class="form-control" type="text" id="NAME" name="NAME" value="">
                            </div>
                        </div>
                        <div class="form-group row">
                            <label for="editSubjectEn" class="col-sm-2 form-control-label">重量：</label>
                            <div class="col-sm-10">
                                <input class="form-control" type="text" id = "WEIGHT" name="WEIGHT" value="">
                            </div>
                        </div>
                        <div class="form-group row">
                            <label for="editSubjectEn" class="col-sm-2 form-control-label">采购厂家：</label>
                            <div class="col-sm-10">
                                <input class="form-control" type="text" id = "CHANGJIANAME" name="CHANGJIANAME" value="">
                            </div>
                        </div>
                        <div class="form-group row">
                            <label for="editSubjectEn" class="col-sm-2 form-control-label">采购链接：</label>
                            <div class="col-sm-10">
                                <input class="form-control" type="text" id = "CHANGJIAURL" name="CHANGJIAURL" value="">
                            </div>
                        </div>
                        <div class="form-group row">
                            <label for="editSubjectEn" class="col-sm-2 form-control-label">备注：</label>
                            <div class="col-sm-10">
                                <input class="form-control" type="text" id = "NOTE" name="NOTE" value="">
                            </div>
                        </div>
                    </div>

                    <div class="form-group row m-t-md">
                        <div class="col-sm-offset-2 col-sm-12">
                            <button type="button" class="btn dark-white p-x-md" data-dismiss="modal">取消</button>
                            <button type="button" id="saveButton" class="btn success p-x-md">提交</button>
                        </div>
                    </div>
                </form>
            </div>

        </div>
    </div>
</div>

<div id="modal-setOffline" class="modal" data-backdrop="true">
    <div class="row-col h-v">
        <div class="row-cell v-m">
            <div class="modal-dialog modal-sm">
                <div class="modal-content">
                    <form role="form" action="" method="POST">
                        {% csrf_token %}
                    <input type="hidden" name="action" value="_offline"/>
                    <input type="hidden" name="offlineProductID" id="offlineProductID" value="0"/>
                    <div class="modal-header">
                        <h5 class="modal-title">提示</h5>
                    </div>
                    <div class="modal-body text-center p-lg">
                        <p>您确定要将产品<code id="offlineProductName" class=""></code>删除吗?</p>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn dark-white p-x-md" data-dismiss="modal">否</button>
                        <button type="submit" id ="delButton" class="btn danger p-x-md" >是</button>
                    </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>


<footer class="light lt p-a">
    <div class="row">
        <div class="col-sm-2 text-left"><small class="text-muted inline m-t-sm m-b-sm">第 1-30 /共 {{ totalCount }} 条</small></div>
        <div class="col-sm-10 text-right text-center-xs">
            <ul class="pagination m-a-0">
                <li><a href="#"><i class="fa fa-chevron-left"></i></a></li>
                {% for pp in pageData %}
                    <li{% if pp.active %} class="active"{% endif %}><a href="?page={{ pp.page }}{% if status %}&status={{ status }}{% endif %}{% if searchType %}&searchType={{ searchType }}{% endif %}{% if searchTxt %}&searchTxt={{ searchTxt }}{% endif %}{% if goodsStock %}&goodsStock={{ goodsStock }}{% endif %}">{{ pp.page }}</a></li>
                {% endfor %}

                <li><a href="#"><i class="fa fa-chevron-right"></i></a></li>
            </ul>
        </div>

    </div>
</footer>
</div>
</div>

<script>
    //编辑
        function  etEditPage(id) {
            var data = {productId:id}
            $.getJSON('/erp/getProductDetail/',data=data,function(result){
                $("#productId").val(id);
                $("#NAME").val(result.NAME);
                $("#WEIGHT").val(result.TOTALWEIGTH);
                $("#CHANGJIANAME").val(result.CHANGJIANAME);
                $("#CHANGJIAURL").val(result.CHANGJIAURL);
                $("#NOTE").val(result.NOTE);
            });
        }
     $(document).on('click', '#saveButton', function() {

     }
     $(document).on('click', '#delButton', function() {
        var productId = $('#productId').val();
        var data={productId:productId}
        $.getJSON('/erp/delProductLibrary/',data,function(result){
                if(result.status==1){
                    alert('删除成功');
                    $('#modal-edit').modal('hide');
                    //window.location.reload();
                }else{
                    alert('删除失败！');
                }
         });
    });


</script>

{% endblock %}
